<?php
namespace app\admin\model;

use think\facade\Request;
use think\Model;

class Goods extends Model{

    public function getAddtimeAttr($v)
    {
       return date('Y-m-d H:i:s',$v);
    }

    public function getIsShowAttr($v,$d)
    {
        $arr = [
            0=>'images/X.jpg',
            1=>'images/z.jpg'
        ];
        return $arr[$d['is_show']];
    }

    public function getIsDownAttr($v,$d)
    {
        $arr = [
            0=>'images/X.jpg',
            1=>'images/z.jpg'
        ];
        return $arr[$d['is_down']];
    }

    public function getIsHotAttr($v,$d)
    {
        $arr = [
            0=>'images/X.jpg',
            1=>'images/z.jpg'
        ];
        return $arr[$d['is_hot']];
    }




















    public function searchGnameAttr($q,$v,$d)
    {
        $q->where('gname','like',"%{$v}%");
    }



    public function searchMinpriceAttr($q,$v,$d)
    {

        $q->where('g.price','>=',$v);
    }
    public function searchMaxpriceAttr($q,$v,$d)
    {

        $q->where('g.price','<=',$v);
    }

    public function searchStartaddtimeAttr($q,$v,$d)
    {

        $q->where('gaddtime','> time',$v);

    }

    public function searchEndaddtimeAttr($q,$v,$d)
    {
        $q->where('gaddtime','< time',$v);
    }

    public function searchIsshowAttr($q,$v,$d)
    {
        $q->where('is_show','=',$v);
    }
    public function searchIshotAttr($q,$v,$d)
    {
        $q->where('is_hot','=',$v);
    }public function searchIsdownAttr($q,$v,$d)
    {
        $q->where('is_down','=',$v);
    }


    


    public static function getGoodsList($where,$order,$all)
    {
         return Goods::alias('g')
            ->join('ecm_category c','g.cid=c.id')
             ->order($order)
            ->field('g.id,gname,photo_x,price,gaddtime,is_hot,is_show,is_down')
            ->field('c.name cname')
            ->withSearch(array_keys($where),$where)
            ->paginate(['list_rows'=>2,'query'=>$all]);
    }


}